package cat.sun.logic;

import cat.sun.data.CellContent;
import cat.sun.data.CellState;
import cat.sun.data.Coordinate;

public class Cell 
{
	private Coordinate position;
	private CellState state;
	private CellContent content;
	private int number;
	
	public Cell(int x, int y)
	{
		this.position = new Coordinate(x, y);
		this.state = CellState.CLOSE;
		this.content = CellContent.NOTHING;
		this.number = 0;
	}
	
	synchronized public CellContent OpenCell()
	{
		this.state = CellState.OPEN;
		return this.content;
	}
	
	public boolean makeBomb()
	{
		if (this.content == CellContent.BOMB) return false;
		this.content = CellContent.BOMB;		
		return true;
	}
	
	public void makeNumber(int number)
	{
		this.number = number;
		this.content = CellContent.NUMBER;
	}
	
	public int getX()
	{
		return this.position.getX();
	}
	
	public int getY()
	{
		return this.position.getY();
	}
	
	synchronized public CellState getState()
	{
		return this.state;
	}
	
	synchronized public int getNumber()
	{
		return this.number;
	}
	
	synchronized  public CellContent getCellContent()
	{
		return this.content;
	}
	
	public boolean Checked()
	{		
		if (this.state == CellState.CHECKED) 
		{
			this.state = CellState.CLOSE;
			return false;
		}
		this.state = CellState.CHECKED;
		return true;
	}
	
	public void CrossCheck()
	{
		this.state = CellState.CROSS_CHECKED;
	}
	
	public void setRedBomb()
	{
		this.content = CellContent.RED_BOMB;
	}
	
}
